package com.google.code.jtasks.manager;

import java.util.Set;

import com.google.code.jtasks.connection.TaskRepoConnectionSettings;
import com.google.code.jtasks.connection.TaskRepoId;
import com.google.inject.ImplementedBy;

/**
 * <p>
 * The factory for {@link ITaskRepoManager} instances, which can be used to interact with task systems. Unlike
 * {@link ITaskRepoManager}s, {@link ITaskRepoManagerFactory}s are guaranteed to be thread-safe.
 * </p>
 * <p>
 * Applications will generally only have one {@link ITaskRepoManagerFactory} that will be used to create new
 * {@link ITaskRepoManager} instances for each task repository operation run.
 * </p>
 */
@ImplementedBy(TaskRepoManagerFactoryImpl.class)
public interface ITaskRepoManagerFactory
{
	/**
	 * Registers a new {@link TaskRepoConnectionSettings} with this {@link ITaskRepoManagerFactory}. Each
	 * {@link TaskRepoConnectionSettings} must be registered before an {@link ITaskRepoManager} can be created
	 * for them via {@link #createRepoManager(TaskRepoId)}.
	 * 
	 * @param connection
	 *            the {@link TaskRepoConnectionSettings} instance to register
	 */
	public void addConnection(TaskRepoConnectionSettings connection);

	/**
	 * Returns the {@link Set} of registered {@link TaskRepoConnectionSettings}s.
	 * 
	 * @return the {@link Set} of registered {@link TaskRepoConnectionSettings}s
	 */
	public Set<TaskRepoConnectionSettings> getConnections();

	/**
	 * Creates a new {@link ITaskRepoManager} instance that can be used to access the task repository
	 * represented by the specified {@link TaskRepoId}. Please note that the
	 * {@link TaskRepoConnectionSettings} associated with the specified {@link TaskRepoId} must first be
	 * registered via {@link #addConnection(TaskRepoConnectionSettings)} before calling this method for the
	 * {@link TaskRepoId}.
	 * 
	 * @param repoId
	 *            the {@link TaskRepoId} associated with the {@link TaskRepoConnectionSettings} to create an
	 *            {@link ITaskRepoManager} for (see {@link TaskRepoConnectionSettings#getTaskRepoId()})
	 * @return a new {@link ITaskRepoManager} instance that can be used to access the task repository
	 *         represented by the specified {@link TaskRepoId}
	 */
	public ITaskRepoManager createRepoManager(TaskRepoId repoId);
}
